package f;

import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import com.pgl.sys.ces.out.ISdkLite;
import f.f0.c;
import g.b0;
import g.e;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;

/* compiled from: HttpUrl */
public final class r {
    public static final char[] j = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    public final String a;
    public final String b;
    public final String c;
    public final String d;
    public final int e;
    public final List<String> f;
    @Nullable
    public final List<String> g;
    @Nullable
    public final String h;
    public final String i;

    /* compiled from: HttpUrl */
    public static final class a {
        @Nullable
        public String a;
        public String b;
        public String c;
        @Nullable
        public String d;
        public int e = -1;
        public final List<String> f;
        @Nullable
        public List<String> g;
        @Nullable
        public String h;

        public a() {
            String str = "";
            this.b = str;
            this.c = str;
            ArrayList arrayList = new ArrayList();
            this.f = arrayList;
            arrayList.add(str);
        }

        public a a(String str, @Nullable String str2) {
            Object b;
            Objects.requireNonNull(str, "encodedName == null");
            if (this.g == null) {
                this.g = new ArrayList();
            }
            this.g.add(r.b(str, " \"'<>#&=", true, false, true, true));
            List list = this.g;
            if (str2 != null) {
                b = r.b(str2, " \"'<>#&=", true, false, true, true);
            } else {
                b = null;
            }
            list.add(b);
            return this;
        }

        public r b() {
            if (this.a == null) {
                throw new IllegalStateException("scheme == null");
            } else if (this.d != null) {
                return new r(this);
            } else {
                throw new IllegalStateException("host == null");
            }
        }

        public a c(@Nullable String str) {
            List p;
            if (str != null) {
                p = r.p(r.b(str, " \"'<>#", true, false, true, true));
            } else {
                p = null;
            }
            this.g = p;
            return this;
        }

        /* JADX WARNING: Removed duplicated region for block: B:133:0x02a3  */
        /* JADX WARNING: Removed duplicated region for block: B:133:0x02a3  */
        /* JADX WARNING: Removed duplicated region for block: B:38:0x00ac  */
        /* JADX WARNING: Removed duplicated region for block: B:30:0x0066  */
        /* JADX WARNING: Removed duplicated region for block: B:193:0x00c7 A:{SYNTHETIC, EDGE_INSN: B:193:0x00c7->B:47:0x00c7 ?: BREAK  , EDGE_INSN: B:193:0x00c7->B:47:0x00c7 ?: BREAK  } */
        /* JADX WARNING: Removed duplicated region for block: B:43:0x00ba  */
        /* JADX WARNING: Removed duplicated region for block: B:62:0x0123  */
        /* JADX WARNING: Removed duplicated region for block: B:61:0x011e  */
        /* JADX WARNING: Removed duplicated region for block: B:85:0x01c3  */
        /* JADX WARNING: Removed duplicated region for block: B:117:0x023a  */
        /* JADX WARNING: Removed duplicated region for block: B:100:0x01e8  */
        /* JADX WARNING: Removed duplicated region for block: B:180:0x03a3  */
        /* JADX WARNING: Removed duplicated region for block: B:120:0x0255  */
        /* JADX WARNING: Missing block: B:108:0x0212, code skipped:
            if (r1 <= 65535) goto L_0x021a;
     */
        public f.r.a d(@javax.annotation.Nullable f.r r22, java.lang.String r23) {
            /*
            r21 = this;
            r0 = r21;
            r1 = r22;
            r10 = r23;
            r2 = r23.length();
            r8 = 0;
            r9 = f.f0.c.w(r10, r8, r2);
            r2 = r23.length();
            r11 = f.f0.c.x(r10, r9, r2);
            r2 = r11 - r9;
            r12 = 2;
            r13 = 58;
            r14 = -1;
            if (r2 >= r12) goto L_0x0020;
        L_0x001f:
            goto L_0x0062;
        L_0x0020:
            r2 = r10.charAt(r9);
            r3 = 90;
            r4 = 122; // 0x7a float:1.71E-43 double:6.03E-322;
            r5 = 65;
            r6 = 97;
            if (r2 < r6) goto L_0x0030;
        L_0x002e:
            if (r2 <= r4) goto L_0x0035;
        L_0x0030:
            if (r2 < r5) goto L_0x0062;
        L_0x0032:
            if (r2 <= r3) goto L_0x0035;
        L_0x0034:
            goto L_0x0062;
        L_0x0035:
            r2 = r9;
        L_0x0036:
            r2 = r2 + 1;
            if (r2 >= r11) goto L_0x0062;
        L_0x003a:
            r7 = r10.charAt(r2);
            if (r7 < r6) goto L_0x0042;
        L_0x0040:
            if (r7 <= r4) goto L_0x005f;
        L_0x0042:
            if (r7 < r5) goto L_0x0046;
        L_0x0044:
            if (r7 <= r3) goto L_0x005f;
        L_0x0046:
            r3 = 48;
            if (r7 < r3) goto L_0x004e;
        L_0x004a:
            r3 = 57;
            if (r7 <= r3) goto L_0x005f;
        L_0x004e:
            r3 = 43;
            if (r7 == r3) goto L_0x005f;
        L_0x0052:
            r3 = 45;
            if (r7 == r3) goto L_0x005f;
        L_0x0056:
            r3 = 46;
            if (r7 != r3) goto L_0x005b;
        L_0x005a:
            goto L_0x005f;
        L_0x005b:
            if (r7 != r13) goto L_0x0062;
        L_0x005d:
            r15 = r2;
            goto L_0x0064;
        L_0x005f:
            r3 = 90;
            goto L_0x0036;
        L_0x0062:
            r2 = -1;
            r15 = -1;
        L_0x0064:
            if (r15 == r14) goto L_0x00ac;
        L_0x0066:
            r3 = 1;
            r6 = 0;
            r7 = 6;
            r5 = "https:";
            r2 = r23;
            r4 = r9;
            r2 = r2.regionMatches(r3, r4, r5, r6, r7);
            if (r2 == 0) goto L_0x007b;
        L_0x0074:
            r2 = "https";
            r0.a = r2;
            r9 = r9 + 6;
            goto L_0x00b2;
        L_0x007b:
            r3 = 1;
            r6 = 0;
            r7 = 5;
            r5 = "http:";
            r2 = r23;
            r4 = r9;
            r2 = r2.regionMatches(r3, r4, r5, r6, r7);
            if (r2 == 0) goto L_0x0090;
        L_0x0089:
            r2 = "http";
            r0.a = r2;
            r9 = r9 + 5;
            goto L_0x00b2;
        L_0x0090:
            r1 = new java.lang.IllegalArgumentException;
            r2 = "Expected URL scheme 'http' or 'https' but was '";
            r2 = c.b.a.a.a.g(r2);
            r3 = r10.substring(r8, r15);
            r2.append(r3);
            r3 = "'";
            r2.append(r3);
            r2 = r2.toString();
            r1.<init>(r2);
            throw r1;
        L_0x00ac:
            if (r1 == 0) goto L_0x03bd;
        L_0x00ae:
            r2 = r1.a;
            r0.a = r2;
        L_0x00b2:
            r2 = 0;
            r3 = r9;
        L_0x00b4:
            r4 = 47;
            r5 = 92;
            if (r3 >= r11) goto L_0x00c7;
        L_0x00ba:
            r6 = r10.charAt(r3);
            if (r6 == r5) goto L_0x00c2;
        L_0x00c0:
            if (r6 != r4) goto L_0x00c7;
        L_0x00c2:
            r2 = r2 + 1;
            r3 = r3 + 1;
            goto L_0x00b4;
        L_0x00c7:
            r3 = 63;
            r6 = 35;
            if (r2 >= r12) goto L_0x010f;
        L_0x00cd:
            if (r1 == 0) goto L_0x010f;
        L_0x00cf:
            r7 = r1.a;
            r8 = r0.a;
            r7 = r7.equals(r8);
            if (r7 != 0) goto L_0x00da;
        L_0x00d9:
            goto L_0x010f;
        L_0x00da:
            r2 = r22.i();
            r0.b = r2;
            r2 = r22.e();
            r0.c = r2;
            r2 = r1.d;
            r0.d = r2;
            r2 = r1.e;
            r0.e = r2;
            r2 = r0.f;
            r2.clear();
            r2 = r0.f;
            r3 = r22.g();
            r2.addAll(r3);
            if (r9 == r11) goto L_0x0104;
        L_0x00fe:
            r2 = r10.charAt(r9);
            if (r2 != r6) goto L_0x010b;
        L_0x0104:
            r1 = r22.h();
            r0.c(r1);
        L_0x010b:
            r17 = r11;
            goto L_0x0256;
        L_0x010f:
            r9 = r9 + r2;
            r1 = 0;
            r2 = 0;
            r14 = r9;
            r1 = -1;
            r12 = 0;
            r15 = 0;
        L_0x0116:
            r2 = "@/\\?#";
            r9 = f.f0.c.k(r10, r14, r11, r2);
            if (r9 == r11) goto L_0x0123;
        L_0x011e:
            r2 = r10.charAt(r9);
            goto L_0x0124;
        L_0x0123:
            r2 = -1;
        L_0x0124:
            if (r2 == r1) goto L_0x01bf;
        L_0x0126:
            if (r2 == r6) goto L_0x01bf;
        L_0x0128:
            if (r2 == r4) goto L_0x01bf;
        L_0x012a:
            if (r2 == r5) goto L_0x01bf;
        L_0x012c:
            if (r2 == r3) goto L_0x01bf;
        L_0x012e:
            r1 = 64;
            if (r2 == r1) goto L_0x0134;
        L_0x0132:
            goto L_0x01b2;
        L_0x0134:
            r8 = "%40";
            if (r12 != 0) goto L_0x0182;
        L_0x0138:
            r7 = f.f0.c.j(r10, r14, r9, r13);
            r5 = 1;
            r6 = 0;
            r16 = 0;
            r17 = 1;
            r18 = 0;
            r4 = " \"':;<=>@[]^`{}|/\\?#";
            r1 = r23;
            r2 = r14;
            r3 = r7;
            r14 = r7;
            r7 = r16;
            r13 = r8;
            r8 = r17;
            r22 = r12;
            r12 = r9;
            r9 = r18;
            r1 = f.r.a(r1, r2, r3, r4, r5, r6, r7, r8, r9);
            if (r15 == 0) goto L_0x0166;
        L_0x015b:
            r2 = new java.lang.StringBuilder;
            r2.<init>();
            r3 = r0.b;
            r1 = c.b.a.a.a.e(r2, r3, r13, r1);
        L_0x0166:
            r0.b = r1;
            if (r14 == r12) goto L_0x017e;
        L_0x016a:
            r2 = r14 + 1;
            r5 = 1;
            r6 = 0;
            r7 = 0;
            r8 = 1;
            r9 = 0;
            r4 = " \"':;<=>@[]^`{}|/\\?#";
            r1 = r23;
            r3 = r12;
            r1 = f.r.a(r1, r2, r3, r4, r5, r6, r7, r8, r9);
            r0.c = r1;
            r1 = 1;
            goto L_0x0180;
        L_0x017e:
            r1 = r22;
        L_0x0180:
            r15 = 1;
            goto L_0x01af;
        L_0x0182:
            r13 = r8;
            r22 = r12;
            r12 = r9;
            r9 = new java.lang.StringBuilder;
            r9.<init>();
            r1 = r0.c;
            r9.append(r1);
            r9.append(r13);
            r5 = 1;
            r6 = 0;
            r7 = 0;
            r8 = 1;
            r13 = 0;
            r4 = " \"':;<=>@[]^`{}|/\\?#";
            r1 = r23;
            r2 = r14;
            r3 = r12;
            r14 = r9;
            r9 = r13;
            r1 = f.r.a(r1, r2, r3, r4, r5, r6, r7, r8, r9);
            r14.append(r1);
            r1 = r14.toString();
            r0.c = r1;
            r1 = r22;
        L_0x01af:
            r14 = r12 + 1;
            r12 = r1;
        L_0x01b2:
            r6 = 35;
            r3 = 63;
            r5 = 92;
            r1 = -1;
            r4 = 47;
            r13 = 58;
            goto L_0x0116;
        L_0x01bf:
            r12 = r9;
            r9 = r14;
        L_0x01c1:
            if (r9 >= r12) goto L_0x01e1;
        L_0x01c3:
            r1 = r10.charAt(r9);
            r2 = 58;
            if (r1 == r2) goto L_0x01df;
        L_0x01cb:
            r3 = 91;
            if (r1 == r3) goto L_0x01d1;
        L_0x01cf:
            r1 = 1;
            goto L_0x01dd;
        L_0x01d1:
            r1 = 1;
        L_0x01d2:
            r9 = r9 + r1;
            if (r9 >= r12) goto L_0x01dd;
        L_0x01d5:
            r3 = r10.charAt(r9);
            r4 = 93;
            if (r3 != r4) goto L_0x01d2;
        L_0x01dd:
            r9 = r9 + r1;
            goto L_0x01c1;
        L_0x01df:
            r13 = r9;
            goto L_0x01e2;
        L_0x01e1:
            r13 = r12;
        L_0x01e2:
            r15 = r13 + 1;
            r9 = 34;
            if (r15 >= r12) goto L_0x023a;
        L_0x01e8:
            r1 = 0;
            r1 = f.r.l(r10, r14, r13, r1);
            r1 = f.f0.c.c(r1);
            r0.d = r1;
            r4 = "";
            r5 = 0;
            r6 = 0;
            r7 = 0;
            r8 = 1;
            r16 = 0;
            r1 = r23;
            r2 = r15;
            r3 = r12;
            r17 = r11;
            r11 = 34;
            r9 = r16;
            r1 = f.r.a(r1, r2, r3, r4, r5, r6, r7, r8, r9);	 Catch:{ NumberFormatException -> 0x0219 }
            r1 = java.lang.Integer.parseInt(r1);	 Catch:{ NumberFormatException -> 0x0219 }
            if (r1 <= 0) goto L_0x0219;
        L_0x020f:
            r2 = 65535; // 0xffff float:9.1834E-41 double:3.23786E-319;
            if (r1 > r2) goto L_0x0219;
        L_0x0214:
            goto L_0x021a;
        L_0x0215:
            r17 = r11;
            r11 = 34;
        L_0x0219:
            r1 = -1;
        L_0x021a:
            r0.e = r1;
            r2 = -1;
            if (r1 == r2) goto L_0x0220;
        L_0x021f:
            goto L_0x0251;
        L_0x0220:
            r1 = new java.lang.IllegalArgumentException;
            r2 = "Invalid URL port: \"";
            r2 = c.b.a.a.a.g(r2);
            r3 = r10.substring(r15, r12);
            r2.append(r3);
            r2.append(r11);
            r2 = r2.toString();
            r1.<init>(r2);
            throw r1;
        L_0x023a:
            r17 = r11;
            r11 = 34;
            r1 = 0;
            r1 = f.r.l(r10, r14, r13, r1);
            r1 = f.f0.c.c(r1);
            r0.d = r1;
            r1 = r0.a;
            r1 = f.r.d(r1);
            r0.e = r1;
        L_0x0251:
            r1 = r0.d;
            if (r1 == 0) goto L_0x03a3;
        L_0x0255:
            r9 = r12;
        L_0x0256:
            r1 = "?#";
            r2 = r17;
            r1 = f.f0.c.k(r10, r9, r2, r1);
            if (r9 != r1) goto L_0x0267;
        L_0x0260:
            r13 = r0;
            r3 = r1;
            r12 = r2;
            r1 = r10;
            r2 = r1;
            goto L_0x0360;
        L_0x0267:
            r3 = r10.charAt(r9);
            r4 = "";
            r5 = 47;
            if (r3 == r5) goto L_0x028b;
        L_0x0271:
            r5 = 92;
            if (r3 != r5) goto L_0x0276;
        L_0x0275:
            goto L_0x028b;
        L_0x0276:
            r3 = r0.f;
            r5 = r3.size();
            r5 = r5 + -1;
            r3.set(r5, r4);
            r7 = r0;
            r8 = r7;
            r3 = r1;
            r11 = r2;
            r6 = r4;
            r13 = r9;
            r2 = r10;
            r4 = r3;
            r1 = r2;
            goto L_0x02a1;
        L_0x028b:
            r3 = 1;
            r5 = r0.f;
            r5.clear();
            r5 = r0.f;
            r5.add(r4);
            r7 = r0;
            r8 = r7;
            r3 = r1;
            r11 = r2;
            r6 = r4;
            r2 = r10;
            r5 = 1;
            r4 = r3;
            r1 = r2;
        L_0x029f:
            r9 = r9 + r5;
        L_0x02a0:
            r13 = r9;
        L_0x02a1:
            if (r13 >= r4) goto L_0x035d;
        L_0x02a3:
            r5 = "/\\";
            r9 = f.f0.c.k(r1, r13, r4, r5);
            if (r9 >= r4) goto L_0x02ad;
        L_0x02ab:
            r5 = 1;
            goto L_0x02ae;
        L_0x02ad:
            r5 = 0;
        L_0x02ae:
            r16 = 1;
            r17 = 0;
            r18 = 0;
            r19 = 1;
            r20 = 0;
            r15 = " \"<>^`{}|/\\?#";
            r12 = r1;
            r14 = r9;
            r12 = f.r.a(r12, r13, r14, r15, r16, r17, r18, r19, r20);
            r13 = ".";
            r13 = r12.equals(r13);
            if (r13 != 0) goto L_0x02d3;
        L_0x02c8:
            r13 = "%2e";
            r13 = r12.equalsIgnoreCase(r13);
            if (r13 == 0) goto L_0x02d1;
        L_0x02d0:
            goto L_0x02d3;
        L_0x02d1:
            r13 = 0;
            goto L_0x02d4;
        L_0x02d3:
            r13 = 1;
        L_0x02d4:
            if (r13 == 0) goto L_0x02d8;
        L_0x02d6:
            goto L_0x0358;
        L_0x02d8:
            r13 = "..";
            r13 = r12.equals(r13);
            if (r13 != 0) goto L_0x02fb;
        L_0x02e0:
            r13 = "%2e.";
            r13 = r12.equalsIgnoreCase(r13);
            if (r13 != 0) goto L_0x02fb;
        L_0x02e8:
            r13 = ".%2e";
            r13 = r12.equalsIgnoreCase(r13);
            if (r13 != 0) goto L_0x02fb;
        L_0x02f0:
            r13 = "%2e%2e";
            r13 = r12.equalsIgnoreCase(r13);
            if (r13 == 0) goto L_0x02f9;
        L_0x02f8:
            goto L_0x02fb;
        L_0x02f9:
            r13 = 0;
            goto L_0x02fc;
        L_0x02fb:
            r13 = 1;
        L_0x02fc:
            if (r13 == 0) goto L_0x032c;
        L_0x02fe:
            r12 = r8.f;
            r13 = r12.size();
            r13 = r13 + -1;
            r12 = r12.remove(r13);
            r12 = (java.lang.String) r12;
            r12 = r12.isEmpty();
            if (r12 == 0) goto L_0x0326;
        L_0x0312:
            r12 = r8.f;
            r12 = r12.isEmpty();
            if (r12 != 0) goto L_0x0326;
        L_0x031a:
            r12 = r8.f;
            r13 = r12.size();
            r13 = r13 + -1;
            r12.set(r13, r6);
            goto L_0x0358;
        L_0x0326:
            r12 = r8.f;
            r12.add(r6);
            goto L_0x0358;
        L_0x032c:
            r13 = r8.f;
            r14 = r13.size();
            r14 = r14 + -1;
            r13 = r13.get(r14);
            r13 = (java.lang.String) r13;
            r13 = r13.isEmpty();
            if (r13 == 0) goto L_0x034c;
        L_0x0340:
            r13 = r8.f;
            r14 = r13.size();
            r14 = r14 + -1;
            r13.set(r14, r12);
            goto L_0x0351;
        L_0x034c:
            r13 = r8.f;
            r13.add(r12);
        L_0x0351:
            if (r5 == 0) goto L_0x0358;
        L_0x0353:
            r12 = r8.f;
            r12.add(r6);
        L_0x0358:
            if (r5 == 0) goto L_0x02a0;
        L_0x035a:
            r5 = 1;
            goto L_0x029f;
        L_0x035d:
            r13 = r7;
            r1 = r10;
            r12 = r11;
        L_0x0360:
            if (r3 >= r12) goto L_0x0387;
        L_0x0362:
            r4 = r2.charAt(r3);
            r5 = 63;
            if (r4 != r5) goto L_0x0387;
        L_0x036a:
            r14 = 35;
            r15 = f.f0.c.j(r2, r3, r12, r14);
            r4 = r3 + 1;
            r7 = 1;
            r8 = 0;
            r9 = 1;
            r10 = 1;
            r11 = 0;
            r6 = " \"'<>#";
            r3 = r1;
            r5 = r15;
            r3 = f.r.a(r3, r4, r5, r6, r7, r8, r9, r10, r11);
            r3 = f.r.p(r3);
            r13.g = r3;
            r3 = r15;
            goto L_0x0389;
        L_0x0387:
            r14 = 35;
        L_0x0389:
            if (r3 >= r12) goto L_0x03a2;
        L_0x038b:
            r2 = r2.charAt(r3);
            if (r2 != r14) goto L_0x03a2;
        L_0x0391:
            r4 = r3 + 1;
            r7 = 1;
            r8 = 0;
            r9 = 0;
            r10 = 0;
            r11 = 0;
            r6 = "";
            r3 = r1;
            r5 = r12;
            r1 = f.r.a(r3, r4, r5, r6, r7, r8, r9, r10, r11);
            r13.h = r1;
        L_0x03a2:
            return r13;
        L_0x03a3:
            r1 = new java.lang.IllegalArgumentException;
            r2 = "Invalid URL host: \"";
            r2 = c.b.a.a.a.g(r2);
            r3 = r10.substring(r14, r13);
            r2.append(r3);
            r2.append(r11);
            r2 = r2.toString();
            r1.<init>(r2);
            throw r1;
        L_0x03bd:
            r1 = new java.lang.IllegalArgumentException;
            r2 = "Expected URL scheme 'http' or 'https' but no colon was found";
            r1.<init>(r2);
            throw r1;
            */
            throw new UnsupportedOperationException("Method not decompiled: f.r$a.d(f.r, java.lang.String):f.r$a");
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder();
            String str = this.a;
            if (str != null) {
                stringBuilder.append(str);
                stringBuilder.append("://");
            } else {
                stringBuilder.append("//");
            }
            if (!(this.b.isEmpty() && this.c.isEmpty())) {
                stringBuilder.append(this.b);
                if (!this.c.isEmpty()) {
                    stringBuilder.append(':');
                    stringBuilder.append(this.c);
                }
                stringBuilder.append('@');
            }
            str = this.d;
            if (str != null) {
                if (str.indexOf(58) != -1) {
                    stringBuilder.append('[');
                    stringBuilder.append(this.d);
                    stringBuilder.append(']');
                } else {
                    stringBuilder.append(this.d);
                }
            }
            int i = this.e;
            if (!(i == -1 && this.a == null)) {
                if (i == -1) {
                    i = r.d(this.a);
                }
                String str2 = this.a;
                if (str2 == null || i != r.d(str2)) {
                    stringBuilder.append(':');
                    stringBuilder.append(i);
                }
            }
            List list = this.f;
            int size = list.size();
            for (int i2 = 0; i2 < size; i2++) {
                stringBuilder.append('/');
                stringBuilder.append((String) list.get(i2));
            }
            if (this.g != null) {
                stringBuilder.append('?');
                r.j(stringBuilder, this.g);
            }
            if (this.h != null) {
                stringBuilder.append('#');
                stringBuilder.append(this.h);
            }
            return stringBuilder.toString();
        }
    }

    public r(a aVar) {
        this.a = aVar.a;
        this.b = m(aVar.b, false);
        this.c = m(aVar.c, false);
        this.d = aVar.d;
        int i = aVar.e;
        if (i == -1) {
            i = d(aVar.a);
        }
        this.e = i;
        this.f = n(aVar.f, false);
        List list = aVar.g;
        String str = null;
        this.g = list != null ? n(list, true) : null;
        String str2 = aVar.h;
        if (str2 != null) {
            str = l(str2, 0, str2.length(), false);
        }
        this.h = str;
        this.i = aVar.toString();
    }

    public static String a(String str, int i, int i2, String str2, boolean z, boolean z2, boolean z3, boolean z4, Charset charset) {
        String str3 = str;
        int i3 = i2;
        String str4 = str2;
        Charset charset2 = charset;
        int i4 = i;
        while (i4 < i3) {
            int codePointAt = str3.codePointAt(i4);
            int i5 = -1;
            if (codePointAt < 32 || codePointAt == 127 || ((codePointAt >= AesLen.ROOTKEY_COMPONET_LEN && z4) || str4.indexOf(codePointAt) != -1 || ((codePointAt == 37 && (!z || (z2 && !o(str3, i4, i3)))) || (codePointAt == 43 && z3)))) {
                e eVar = new e();
                eVar.H0(str3, i, i4);
                e eVar2 = null;
                while (i4 < i3) {
                    int codePointAt2 = str3.codePointAt(i4);
                    if (!(z && (codePointAt2 == 9 || codePointAt2 == 10 || codePointAt2 == 12 || codePointAt2 == 13))) {
                        if (codePointAt2 == 43 && z3) {
                            eVar.G0(z ? "+" : "%2B");
                        } else if (codePointAt2 < 32 || codePointAt2 == 127 || ((codePointAt2 >= AesLen.ROOTKEY_COMPONET_LEN && z4) || str4.indexOf(codePointAt2) != i5 || (codePointAt2 == 37 && (!z || (z2 && !o(str3, i4, i3)))))) {
                            if (eVar2 == null) {
                                eVar2 = new e();
                            }
                            if (charset2 == null || charset2.equals(c.j)) {
                                eVar2.I0(codePointAt2);
                            } else {
                                i5 = Character.charCount(codePointAt2) + i4;
                                if (i4 < 0) {
                                    throw new IllegalAccessError(c.b.a.a.a.A("beginIndex < 0: ", i4));
                                } else if (i5 < i4) {
                                    StringBuilder stringBuilder = new StringBuilder();
                                    stringBuilder.append("endIndex < beginIndex: ");
                                    stringBuilder.append(i5);
                                    stringBuilder.append(" < ");
                                    stringBuilder.append(i4);
                                    throw new IllegalArgumentException(stringBuilder.toString());
                                } else if (i5 > str.length()) {
                                    StringBuilder h = c.b.a.a.a.h("endIndex > string.length: ", i5, " > ");
                                    h.append(str.length());
                                    throw new IllegalArgumentException(h.toString());
                                } else if (charset2.equals(b0.a)) {
                                    eVar2.H0(str3, i4, i5);
                                } else {
                                    byte[] bytes = str3.substring(i4, i5).getBytes(charset2);
                                    eVar2.A0(bytes, 0, bytes.length);
                                }
                            }
                            while (!eVar2.Q()) {
                                i5 = eVar2.q0() & ISdkLite.REGION_UNSET;
                                eVar.B0(37);
                                char[] cArr = j;
                                eVar.B0(cArr[(i5 >> 4) & 15]);
                                eVar.B0(cArr[i5 & 15]);
                            }
                        } else {
                            eVar.I0(codePointAt2);
                        }
                    }
                    i4 += Character.charCount(codePointAt2);
                    i5 = -1;
                }
                return eVar.s0();
            }
            i4 += Character.charCount(codePointAt);
        }
        int i6 = i;
        return str.substring(i, i2);
    }

    public static String b(String str, String str2, boolean z, boolean z2, boolean z3, boolean z4) {
        return a(str, 0, str.length(), str2, z, z2, z3, z4, null);
    }

    public static String c(String str, String str2, boolean z, boolean z2, boolean z3, boolean z4, Charset charset) {
        return a(str, 0, str.length(), str2, z, z2, z3, z4, null);
    }

    public static int d(String str) {
        if (str.equals("http")) {
            return 80;
        }
        return str.equals("https") ? 443 : -1;
    }

    public static void j(StringBuilder stringBuilder, List<String> list) {
        int size = list.size();
        for (int i = 0; i < size; i += 2) {
            String str = (String) list.get(i);
            String str2 = (String) list.get(i + 1);
            if (i > 0) {
                stringBuilder.append('&');
            }
            stringBuilder.append(str);
            if (str2 != null) {
                stringBuilder.append('=');
                stringBuilder.append(str2);
            }
        }
    }

    public static String l(String str, int i, int i2, boolean z) {
        int i3 = i;
        while (i3 < i2) {
            char charAt = str.charAt(i3);
            if (charAt == '%' || (charAt == '+' && z)) {
                e eVar = new e();
                eVar.H0(str, i, i3);
                while (i3 < i2) {
                    i = str.codePointAt(i3);
                    if (i == 37) {
                        int i4 = i3 + 2;
                        if (i4 < i2) {
                            int h = c.h(str.charAt(i3 + 1));
                            int h2 = c.h(str.charAt(i4));
                            if (!(h == -1 || h2 == -1)) {
                                eVar.B0((h << 4) + h2);
                                i3 = i4;
                                i3 += Character.charCount(i);
                            }
                            eVar.I0(i);
                            i3 += Character.charCount(i);
                        }
                    }
                    if (i == 43 && z) {
                        eVar.B0(32);
                        i3 += Character.charCount(i);
                    }
                    eVar.I0(i);
                    i3 += Character.charCount(i);
                }
                return eVar.s0();
            }
            i3++;
        }
        return str.substring(i, i2);
    }

    public static String m(String str, boolean z) {
        return l(str, 0, str.length(), z);
    }

    public static boolean o(String str, int i, int i2) {
        int i3 = i + 2;
        if (i3 >= i2 || str.charAt(i) != '%' || c.h(str.charAt(i + 1)) == -1 || c.h(str.charAt(i3)) == -1) {
            return false;
        }
        return true;
    }

    public static List<String> p(String str) {
        ArrayList arrayList = new ArrayList();
        int i = 0;
        while (i <= str.length()) {
            int indexOf = str.indexOf(38, i);
            if (indexOf == -1) {
                indexOf = str.length();
            }
            int indexOf2 = str.indexOf(61, i);
            if (indexOf2 == -1 || indexOf2 > indexOf) {
                arrayList.add(str.substring(i, indexOf));
                arrayList.add(null);
            } else {
                arrayList.add(str.substring(i, indexOf2));
                arrayList.add(str.substring(indexOf2 + 1, indexOf));
            }
            i = indexOf + 1;
        }
        return arrayList;
    }

    public String e() {
        if (this.c.isEmpty()) {
            return "";
        }
        return this.i.substring(this.i.indexOf(58, this.a.length() + 3) + 1, this.i.indexOf(64));
    }

    public boolean equals(@Nullable Object obj) {
        return (obj instanceof r) && ((r) obj).i.equals(this.i);
    }

    public String f() {
        int indexOf = this.i.indexOf(47, this.a.length() + 3);
        String str = this.i;
        return this.i.substring(indexOf, c.k(str, indexOf, str.length(), "?#"));
    }

    public List<String> g() {
        int indexOf = this.i.indexOf(47, this.a.length() + 3);
        String str = this.i;
        int k = c.k(str, indexOf, str.length(), "?#");
        ArrayList arrayList = new ArrayList();
        while (indexOf < k) {
            indexOf++;
            int j = c.j(this.i, indexOf, k, '/');
            arrayList.add(this.i.substring(indexOf, j));
            indexOf = j;
        }
        return arrayList;
    }

    @Nullable
    public String h() {
        if (this.g == null) {
            return null;
        }
        int indexOf = this.i.indexOf(63) + 1;
        String str = this.i;
        return this.i.substring(indexOf, c.j(str, indexOf, str.length(), '#'));
    }

    public int hashCode() {
        return this.i.hashCode();
    }

    public String i() {
        if (this.b.isEmpty()) {
            return "";
        }
        int length = this.a.length() + 3;
        String str = this.i;
        return this.i.substring(length, c.k(str, length, str.length(), ":@"));
    }

    public a k() {
        String str;
        a aVar = new a();
        aVar.a = this.a;
        aVar.b = i();
        aVar.c = e();
        aVar.d = this.d;
        aVar.e = this.e != d(this.a) ? this.e : -1;
        aVar.f.clear();
        aVar.f.addAll(g());
        aVar.c(h());
        if (this.h == null) {
            str = null;
        } else {
            str = this.i.substring(this.i.indexOf(35) + 1);
        }
        aVar.h = str;
        return aVar;
    }

    public final List<String> n(List<String> list, boolean z) {
        int size = list.size();
        ArrayList arrayList = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            String str = (String) list.get(i);
            arrayList.add(str != null ? l(str, 0, str.length(), z) : null);
        }
        return Collections.unmodifiableList(arrayList);
    }

    public URI q() {
        a k = k();
        int size = k.f.size();
        for (int i = 0; i < size; i++) {
            k.f.set(i, b((String) k.f.get(i), "[]", true, true, false, true));
        }
        List list = k.g;
        if (list != null) {
            size = list.size();
            for (int i2 = 0; i2 < size; i2++) {
                String str = (String) k.g.get(i2);
                if (str != null) {
                    k.g.set(i2, b(str, "\\^`{|}", true, true, true, true));
                }
            }
        }
        String str2 = k.h;
        if (str2 != null) {
            k.h = b(str2, " \"#<>\\^`{|}", true, true, false, false);
        }
        String aVar = k.toString();
        try {
            return new URI(aVar);
        } catch (URISyntaxException e) {
            try {
                return URI.create(aVar.replaceAll("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]", ""));
            } catch (Exception unused) {
                throw new RuntimeException(e);
            }
        }
    }

    public String toString() {
        return this.i;
    }
}
